package com.nativetalk.controller.app.three.member;

import com.nativetalk.base.RetInfo;
import com.nativetalk.bean.FoundChange.TdNtMembFoundChangeList;
import com.nativetalk.bean.member.TdNtMember;
import com.nativetalk.bean.member.TdNtMemberBinding;
import com.nativetalk.bean.member.TdNtMemberThirdRegister;
import com.nativetalk.bean.sms.Sms;
import com.nativetalk.bean.teacher.TdNtTeacherDetail;
import com.nativetalk.bean.website.TsNtWebSiteConfIndex;
import com.nativetalk.common.Constants;
import com.nativetalk.common.Lang;
import com.nativetalk.common.ValidationMessages;
import com.nativetalk.common.util.*;
import com.nativetalk.service.three.book.search.ThreeBookSearchServiceImpl;
import com.nativetalk.service.three.member.register.ThreeMemberRegisterService;
import com.nativetalk.service.three.member.search.ThreeMemberSearchService;
import com.nativetalk.service.three.member.update.ThreeMemberUpdateService;
import com.nativetalk.service.three.purchase.insert.ThreePurchaseInsertService;
import com.nativetalk.service.three.teacher.search.ThreeTeacherSearchService;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lizhun on 15/12/9.
 */
@Controller
public class ThreeMemberController {
    private static Logger logger = Logger.getLogger(ThreeMemberController.class);
    @Resource
    private ThreeMemberUpdateService threeMemberUpdateService;
    @Resource
    private ThreeTeacherSearchService threeTeacherSearchService;
    @Resource
    private ThreeMemberRegisterService threeMemberRegisterService;
    @Resource
    private ThreePurchaseInsertService threePurchaseInsertService;
    @Resource
    private ThreeMemberSearchService threeMemberSearchService;
    @Resource
    private ThreeBookSearchServiceImpl threeBookSearchServiceImpl;

    /**
     * @param token
     * @return RetInfo
     * @Purpose 我的 --> 首页
     * @version 3.2
     * @time 2016-08-26
     * @author lizhun
     */
    @RequestMapping(value = "/app/8/token/member/me", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo me(@RequestHeader(value = "token", required = false) String token) {
        Map<String, Object> map = new HashMap<>();
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(map));

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;

            RetInfo retInfo = new RetInfo();
            map.put("memb_head_portrait", tdNtMember.getMemb_head_portrait());
            map.put("memb_name", tdNtMember.getMemb_name());
            map.put("memb_phone", tdNtMember.getMemb_phone());
            map.put("memb_sex", tdNtMember.getMemb_sex());
            map.put("memb_phone_area", tdNtMember.getMemb_phone_area());
            map.put("video_switch", tdNtMember.getVideo_switch());

            // 查询购买的总课时和已完成课时
            threeBookSearchServiceImpl.index(tdNtMember, map);

            retInfo.setMark(ValidationMessages.getValue("MARKYES"));
            retInfo.setTip("获取数据成功");
            retInfo.setObj(map);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @return RetInfo
     * @Purpose 绑定或更换绑定手机号
     * @version 3.0
     * @time    2015-06-15
     * @author lizhun
     */
    @RequestMapping(value = "/app/6/token/member/binding", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo binding(HttpServletRequest request, @RequestBody TdNtMemberBinding tdNtMemberBinding,
                           @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(tdNtMemberBinding));

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;
            RetInfo retInfo;
            tdNtMember.setMemb_phone(tdNtMemberBinding.getMemb_email());
            String memb_password = tdNtMemberBinding.getMemb_password();
            if(null !=  memb_password && 0 < memb_password.trim().length()){
                tdNtMember.setMemb_password(MD5.code(memb_password));
            }
            retInfo = threeMemberUpdateService.updateMmeberPhone(tdNtMember,tdNtMemberBinding.getCode());

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }
    /**
     * @return RetInfo
     * @Purpose 绑定手机号发送短信
     * @version 3.0
     * @time    2015-06-15
     * @author lizhun
     */
    @RequestMapping(value = "/app/6/token/member/binding/sendMsg", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo sendMsg(HttpServletRequest request, @RequestBody Sms sms,
                           @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(sms));

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;
            RetInfo retInfo;
            tdNtMember.setMemb_phone(sms.getMemb_phone());
            tdNtMember.setMemb_phone_area(sms.getMemb_phone_area());
            retInfo = threeMemberUpdateService.updateMmeberPhoneSendMessage(tdNtMember);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }
    /**
     * @return RetInfo
     * @Purpose 随机查找老师供学生关注
     * @version 3.0
     * @time    2015-06-15
     * @author lizhun
     */
    @RequestMapping(value = "/app/6/token/member/teacher/random", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo random() {
        try {
            //打印入参
            logger.info(Constants.prefix_in);

            RetInfo retInfo;
            retInfo = threeTeacherSearchService.findTeacherRomand();

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @return RetInfo
     * @Purpose 学生关注老师
     * @version 3.0
     * @time    2015-06-15
     * @author lizhun
     */
    @RequestMapping(value="/app/6/token/member/teacher/random/follow" ,method = {RequestMethod.GET, RequestMethod.POST},consumes = "application/json")
    @ResponseBody
    public RetInfo follow(@RequestBody Map<String,TdNtTeacherDetail[]> mapParams,
                           @RequestHeader(value = "token", required = true) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(mapParams));

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;
            RetInfo retInfo;
            List<Map<String, Object>> list = new ArrayList<>();
            TdNtTeacherDetail[] mapParam = mapParams.get("tea_id");
            for (int i = 0 ; i < mapParam.length ; i ++) {
                Map<String, Object> map = new HashMap<>();
                map.put("tea_id",mapParam[i].getTea_id());
                map.put("memb_id",tdNtMember.getMemb_id());
                map.put("collection_flag", 0);
                list.add(i,map);
            }
            retInfo = threeTeacherSearchService.updateTeacherCollect(list);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }
    /**
     * @return RetInfo
     * @Purpose 获取注册奖励
     * @version 3.0
     * @time    2015-06-15
     * @author lizhun
     */
    @RequestMapping(value = "/app/6/token/member/register/reward", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo reward(HttpServletRequest request, @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in);

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;
            RetInfo retInfo = new RetInfo();
            retInfo.setMark("0");
            retInfo.setTip("获取注册奖励");
            Map<String, Object> find  = new HashMap<>();
            find.put("memb_id",tdNtMember.getMemb_id());
            find.put("mfchg_change_name","注册奖励");
            TdNtMembFoundChangeList tdNtMembFoundChangeList = threeMemberUpdateService.findMemberByRegister(find);
            Map<String, Object>  map = new HashMap<>();
            if (tdNtMembFoundChangeList != null){
                map.put("binding_reward", 0);
            } else {
                Map<String, TsNtWebSiteConfIndex> tsNtWebSiteConfIndexMap = (Map<String, TsNtWebSiteConfIndex>) MemcachedUtils.get(MemcachedKey.tsNtWebSiteConfIndexMap);
                BigDecimal binding = new BigDecimal(tsNtWebSiteConfIndexMap.get("27").getData_value());

                map.put("binding_reward", binding);
            }

            map.put("binding_reward_picture", "waijiaojun/app/image/binding_reward.png");
            retInfo.setObj(map);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }
    /**
     * @return RetInfo
     * @Purpose 领取注册奖励
     * @version 3.0
     * @time    2015-06-15
     * @author lizhun
     */
    @RequestMapping(value = "/app/6/token/member/register/reward/receive", method = {RequestMethod.GET, RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public RetInfo receive(HttpServletRequest request,
                          @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in);

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;
            RetInfo retInfo = threeMemberUpdateService.memberBindingReward(tdNtMember);

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }


    /**
     * @Purpose  第三方登陆
     * {"memb_head_portrait":"http:\/\/wx.qlogo.cn\/mmopen\/ajNVdqHZLLDArX7ou0INiaUhmNOUOYoibNp6IoaRLplc0QZl8TxwrIjrlibnwX81icQF79rC2WseCEicd1bRlTy38Ew\/0",
     * "equ_client_id":"62b7977190815dd1daa2b79ed9ea3933929f754b9df0a04357be1c719f981964",
     * "memb_name":"...(^ ^)",
     * "third_token":"oeq04v3DlB7bu7I60gtW34WmlbgY"}
     * @version  2.1
     * @time     2016-05-22
     * @author   lizhun
     * @param    tdNtMemberThirdRegister
     * @return   RetInfo
     */
    @RequestMapping(value="/app/6/member/third/register" ,method = {RequestMethod.GET,RequestMethod.POST} ,consumes = "application/json")
    @ResponseBody
    public RetInfo register(HttpServletRequest request,@Valid @RequestBody TdNtMemberThirdRegister tdNtMemberThirdRegister, BindingResult result,
                            @RequestHeader(value = "client_type", required = true) String client_type,
                            @RequestHeader(value = "version", required = true) Integer version) {
        RetInfo retInfo = new RetInfo();
        if (result.hasErrors())   {
            List<FieldError> err=result.getFieldErrors();
            FieldError fe = err.get(0);
            retInfo.setMark(ValidationMessages.getValue("MARKPARAMETERERROR"));
            retInfo.setTip(fe.getDefaultMessage());
        }else {
            try {
                //打印入参
                logger.info(Constants.prefix_in + JsonUtil.toJson(tdNtMemberThirdRegister));

                if (version >= 6) {
                    tdNtMemberThirdRegister.setEqu_type(client_type);
                    retInfo = threeMemberRegisterService.thirdregister(tdNtMemberThirdRegister, Ip.getIpAddr(request));
                } else {
                    retInfo.setMark("1");
                    retInfo.setTip("请更新最新版本");
                }

                //打印出参
                logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
                return retInfo;
            } catch (Exception e) {
                //记录错误日志
                retInfo = RetInfo.getServerErrorInfo();
                logger.error(e.getMessage(), e);

                //打印出参
                logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
                return retInfo;
            }
        }
        return retInfo;
    }
    /**
     * @Purpose  苹果内购充值
     * @version  3.1
     * @time     2016-08-12
     * @author   lizhun
     * @param    mapParams
     * @return   RetInfo
     */
    @RequestMapping(value="/app/7/token/member/purchase" ,method = {RequestMethod.GET,RequestMethod.POST} ,consumes = "application/json")
    @ResponseBody
    public RetInfo purchase(@RequestBody Map<String,Integer> mapParams,
                            @RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in + JsonUtil.toJson(mapParams));

            RetInfo retInfo;
            TdNtMember tdNtMember = (TdNtMember) MemcachedUtils.get(token);
            retInfo = threePurchaseInsertService.purchase(tdNtMember.getMemb_id(), mapParams.get("purchase_amount"));

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }
    /**
     * @Purpose  苹果内购充值
     * @version  3.1
     * @time     2016-08-12
     * @author   lizhun
     * @param    token
     * @return   RetInfo
     */
    @RequestMapping(value="/app/7/token/member/purchase/balance" ,method = {RequestMethod.GET,RequestMethod.POST} ,consumes = "application/json")
    @ResponseBody
    public RetInfo balance(@RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in);

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;
            RetInfo retInfo = threeMemberSearchService.getPurchase(tdNtMember.getMemb_id());

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }

    /**
     * @Purpose  获取余额和内购余额
     * @version  3.2
     * @time     2016-08-26
     * @author   lizhun
     * @param    token
     * @return   RetInfo
     */
    @RequestMapping(value="/app/8/token/member/balance" ,method = {RequestMethod.GET,RequestMethod.POST} ,consumes = "application/json")
    @ResponseBody
    public RetInfo purchaseAndBalance(@RequestHeader(value = "token", required = false) String token) {
        try {
            //打印入参
            logger.info(Constants.prefix_in);

            //校验token，如果校验通过就从缓存中读取Member
            if (StringUtils.isBlank(token)) {
                RetInfo retInfo = RetInfo.getClientErrorInfo("Parameter token  is required");
                logger.info(JsonUtil.toJson(retInfo));
                return retInfo;
            }
            Object o = MemcachedUtils.get(token);
            if (o == null) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存中没有MemberToken:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }

            if (!TdNtMember.class.isInstance(o)) {
                RetInfo retInfo = RetInfo.getReloginInfo(Lang.ZH);
                logger.info("缓存的token不是TdNtMember类型:[" + token + "]，用户需要重新登录系统。 retInfo-->" + JsonUtil.toJson(retInfo));
                return retInfo;
            }
            TdNtMember tdNtMember = (TdNtMember) o;
            RetInfo retInfo = threeMemberSearchService.getPurchaseAndBalance(tdNtMember.getMemb_id());

            //打印出参
            logger.info(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        } catch (Exception e) {
            //记录错误日志
            RetInfo retInfo = RetInfo.getServerErrorInfo();
            logger.error(e.getMessage(), e);

            //打印出参
            logger.error(Constants.prefix_out + JsonUtil.toJson(retInfo));
            return retInfo;
        }
    }
}



